package com.wedding.mq;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeoutException;

import org.junit.Test;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConfirmListener;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConsumerCancelledException;
import com.rabbitmq.client.QueueingConsumer;
import com.rabbitmq.client.QueueingConsumer.Delivery;
import com.rabbitmq.client.ShutdownSignalException;

public class MQExchangeStudy2 {

	public static void main(String[] args) throws IOException, TimeoutException {
		Connection connection = MQUtil.getConnection();
		Channel channel = connection.createChannel();
		channel.confirmSelect();

        String exchange = "amq.direct";
        String routingKey = "xx";
        String message = "test confirm";
        channel.basicPublish(exchange, routingKey, null, message.getBytes());
        //添加确认监听
        channel.addConfirmListener(new ConfirmListener() {
            //消息成功发送回调
            public void handleAck(long deliverTag, boolean multiple) throws IOException {
                System.err.println("----发送成功---");
            }
            //消息发送失败回调
            public void handleNack(long deliverTag, boolean multiple) throws IOException {
            	//队列满、磁盘满 等等情况
                System.err.println("----发送失败---");
            }
        });
		
	}
	
	
}
